package org.tt.sudoku;

import android.app.Activity;
import android.os.Bundle;

public class Sudoku extends Activity {
    
	public final String easySudoku =
		"360000000004230800000004200" +
		"070460003820000014500013020" +
		"001900000007048300000000045" ;
	
	private int puzzle[] = new int[9*9];
	
	private SudokuView sudoku;
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        puzzle = fromStringToPuzzle(easySudoku);
        
        sudoku = new SudokuView(this);
        
        setContentView(sudoku);
    }
    
    /** Return the tile at the given coordinates */
    private int getTile(int x, int y) {
    	return puzzle[y * 9 + x];
    }
    
    /** Change the tile at the given coordinates */
    protected void setTile(int x, int y, int value) {
    	puzzle[y * 9 + x] = value;
    }
    
    /** Convert an array into a puzzle string */
    static private String toPuzzleString(int[] puz) {
	    StringBuilder buf = new StringBuilder();
	    for (int element : puz) {
	    	buf.append(element);
	    }
	    return buf.toString();
    }
    
    /** Convert a puzzle string into an array */
    static protected int[] fromStringToPuzzle(String string) {
	    int[] puz = new int[string.length()];
	    for (int i = 0; i < puz.length; i++) {
	    	puz[i] = string.charAt(i) - '0' ;
	    }
	    return puz;
    }
    /** Return a string for the tile at the given coordinates */
    protected String getTileString(int x, int y) {
	    int v = getTile(x, y);
	    if (v == 0)
	    	return "" ;
	    else
	    	return String.valueOf(v);
    }
    
}